/**
 * 项目名：	Rumba Plan
 * 
 * 版权所有(C)，上海海鼎信息工程股份有限公司，2007，所有权利保留。
 * 
 * 文件名：	PrintTest.java
 * 模块说明：	
 * 修改历史：
 * Jun 8, 2007 - zhangyanbo - 创建。
 */
package com.hd123.rumba.report;

import java.util.Date;

/**
 * @author zhangyanbo
 * 
 */
public class ReportTest {

  public static void main(String[] args) throws Exception {
    ReportTest pt = new ReportTest();
    pt.test1();
    System.out.println();
    System.out.println();
    pt.test2();
  }

  public void test1() throws Exception {
    DataPacketBuilder builder = DataPacketBuilder.getBuilder(System.out);
    // -------------------------- 表定义
    // 主表
    TableDef def = builder.getTableDef();
    def.addField("code", Field.STRING, true, 10);
    def.addField("age", Field.INTEGER);
    def.addField("items", Field.NESTED);
    def.addField("birth", Field.DATETIME);
    def.addField("total", Field.DECIMAL, false, 19).setDecimals(4);
    def.addField("lines", Field.NESTED);
    // 一级嵌套表
    TableDef def2 = def.getTableDef("lines");
    def2.addField("lineNumber", Field.INTEGER);
    def2.addField("productCode", Field.STRING, false, 20);
    // 一级嵌套表
    TableDef def3 = def.getTableDef("items");
    def3.addField("itemNo", Field.INTEGER);
    def3.addField("name", Field.STRING, true, 15);
    def3.addField("sublines", Field.NESTED);
    // 二级嵌套表
    TableDef def4 = def3.getTableDef("sublines");
    def4.addField("sublineNo", Field.INTEGER);
    def4.addField("testfield", Field.DECIMAL, false, 19).setDecimals(2);

    // -------------------------表数据
    TableData data = builder.getTableData();
    data.append();
    data.write("code", "测试code");
    data.write("age", Integer.valueOf(10));
    TableData items = data.getTableData("items");
    items.append();
    items.write("itemNo", Integer.valueOf(33));
    items.write("name", "this is name");
    TableData sublines = items.getTableData("sublines");
    sublines.append();
    sublines.write("sublineNo", Integer.valueOf(12345));
    sublines.write("testfield", Double.valueOf(123.12356));
    sublines.post();
    items.post();
    items.append();
    items.write("itemNo", Integer.valueOf(44));
    items.write("name", "this is another name");
    sublines = items.getTableData("sublines");
    sublines.append();
    sublines.write("sublineNo", Integer.valueOf(6789));
    sublines.write("testfield", Double.valueOf(-10.192));
    sublines.post();
    items.post();
    data.write("birth", new Date());
    data.write("total", Double.valueOf(100.2345));
    TableData lines = data.getTableData("lines");
    lines.append();
    lines.write("lineNumber", Integer.valueOf(1));
    lines.write("productCode", "00000111");
    lines.post();
    lines.append();
    lines.write("lineNumber", Integer.valueOf(2));
    lines.write("productCode", "000000222");
    lines.post();
    data.post();

    builder.build();
  }

  public void test2() throws Exception {
    DataPacketBuilder builder = DataPacketBuilder.getBuilder(System.out);
    TableDef def = builder.getTableDef();
    def.addField("code", Field.STRING, true);
    def.addField("age", Field.INTEGER);
    def.addField("birth", Field.DATETIME);
    def.addField("total", Field.DECIMAL);

    TableData data = builder.getTableData();

    data.append();
    data.write("code", "测试code");
    data.write("age", Integer.valueOf(10));
    data.write("birth", new Date());
    data.write("total", Double.valueOf(100.2345));
    data.post();

    builder.build();
  }
}
